package com.yequan.exe.business;

import com.yequan.exe.core.annotation.ExeService;
import com.yequan.exe.core.handler.AbstractExeHandler;
import com.yequan.exe.core.ExeExecutorExtListener;
import com.yequan.pojo.CalcData;
import com.yequan.pojo.ExeInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author yq
 * @date 2020/09/29
 */
@ExeService("unzipExeHandler")
public class UnzipExeHandler extends AbstractExeHandler implements ExeExecutorExtListener {

    @Override
    public void combineCommand(CalcData calcData) {
        ExeInfo exeInfo = calcData.getExeInfo();
        Map<String, String> paramMap = exeInfo.getParamMap();
        List<String> command = new ArrayList<>();
        command.add(exeInfo.getExeName());
        command.add("-jar");
        command.add(paramMap.get("jarPath"));
        command.add(paramMap.get("sourceUnzipFilePath"));
        command.add(paramMap.get("targetUnzipPath1"));
        command.add(paramMap.get("targetUnzipPath2"));
        exeInfo.setCommand(command);
    }

    @Override
    public ExeExecutorExtListener getExeExecutorListener() {
        return this;
    }

    @Override
    public void afterExecuteExt(CalcData calcData, int result) {
        System.out.println(Thread.currentThread().getName() + "执行结果：" + result);
    }
}
